/*********************
* Author:Dzlua
* QQ:505544956
* time:2016/12/13
*/
#include "LuaSurface.h"
#include "../edui.h"

#ifdef EDUI_USE_LUAPLUS

EDUI_NAMESPACE_BEGIN

#ifdef EDUI_TEST_NEW_DELETE
int LuaSurface::m_newdeleteNum = 0;
int LuaSurface::_GetNewDeleteNum()
{
    return m_newdeleteNum;
}
#endif

void* LuaSurface::GetInterface(void* data)
{
    if (!data) return 0;
    LuaSurface* surface = new LuaSurface((ISurface*)data);
#ifdef EDUI_TEST_NEW_DELETE
    ++m_newdeleteNum;
    Log("[LuaSurface] new LuaSurface : %d, %d", surface, data);
#endif
    return surface;
}

void LuaSurface::Release()
{
#ifdef EDUI_TEST_NEW_DELETE
    --m_newdeleteNum;
    Log("[LuaSurface] delete LuaSurface : %d, %d", this, m_cobj);
#endif
    delete this;
}

void* LuaSurface::GetCObj()
{
    return m_cobj;
}

LuaSurface::LuaSurface(ISurface* surface)
{
    m_cobj = surface;
}

LuaSurface::~LuaSurface()
{}

//----------------------------------------//

//----------------------------------------//

void LuaSurface::Register(LuaState *L)
{
    LuaObject obj = LuaHelperNS::AddToMetas(L, "Surface");
    obj.SetObject("__index", obj);
    obj.RegisterDirect("__NewCObj__", &LuaSurface::GetInterface);
    
}

EDUI_NAMESPACE_END

#endif